<template>
	<view class="" style="overflow: hidden;">
		<template v-if="info">
			<fui-card title="基础信息" :margin="['32rpx', '24rpx']">
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">城市/部门：</view>
					<view class="">{{ `${info.city_name} - ${info.departments_name}` }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">战队：</view>
					<view class="">{{ info.team }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">签单人：</view>
					<view class="">{{ info.sign_person }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">签单日期：</view>
					<view class="">{{ info.sign_date }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">获客渠道：</view>
					<view class="">{{ info.channel_name }}</view>
				</fui-list-cell>
			</fui-card>

			<fui-card title="客户信息" :margin="['32rpx', '24rpx']">
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">客户类型：</view>
					<view class="">{{ info.customer_type_name }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">公司名称：</view>
					<view class="">{{ info.company_name }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">客户姓名：</view>
					<view class="">{{ info.customer_name }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">公司类型：</view>
					<view class="">{{ companyTypeFormat(info.customer_category) }}</view>
				</fui-list-cell>
			</fui-card>

			<fui-card title="产品及收款" :margin="['32rpx', '24rpx']">
				<view v-for="(item, index) in info.products" :key="index" class="">
					<fui-section :title="`产品及收款${index + 1}`" isLine lineWidth="5px" marginTop="28"
						marginBottom="16"></fui-section>
					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">产品类型：</view>
						<view class="">{{ `${item.product_type_name}--${item.product_subdivision_name}` }}</view>
					</fui-list-cell>
					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">实际收款：</view>
						<view class="">{{ item.actual_payment }}</view>
					</fui-list-cell>
					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">帐套启用时间：</view>
						<view class="">{{ item.account_start_date }}</view>
					</fui-list-cell>

					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">代账起始时间：</view>
						<view class="">{{ item.agency_start_month }}</view>
					</fui-list-cell>
					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">代账终止时间：</view>
						<view class="">{{ item.agency_end_month }}</view>
					</fui-list-cell>
					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">代账月份：</view>
						<view v-if="item.agency_months" class="">{{ item.agency_months }}</view>
					</fui-list-cell>
					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">注册区域：</view>
						<view class="">{{ item.register_region }}</view>
					</fui-list-cell>
					<fui-list-cell :padding="['12px', '32rpx']">
						<view class="fs-color__subtitle">是否加急：</view>
						<view class="">{{ item.is_urgent }}</view>
					</fui-list-cell>
					<fui-card :title="`成本总额：${item.costTotal}元`" shadow="none" :padding="['20rpx', '0']"
						:margin="['0', '32rpx']" :showBorder="false">
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">刻章成本：</view>
								<view class="">{{ item.cost.kezhang_chengben }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">报税软件：</view>
								<view class="">{{ item.cost.baoshui_ruanjian }}</view>
							</view>
						</fui-list-cell>
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">数字证书：</view>
								<view class="">{{ item.cost.shuzi_zhengshu }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">渠道成本：</view>
								<view class="">{{ item.cost.qudao_chengben }}</view>
							</view>
						</fui-list-cell>
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">园区地址：</view>
								<view class="">{{ item.cost.yuanqu_dizhi }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">加急费用：</view>
								<view class="">{{ item.cost.jiaji_feiyong }}</view>
							</view>
						</fui-list-cell>
					</fui-card>
					<fui-card :title="`毛利总额：${item.profitTotal}元`" shadow="none" :padding="['20rpx', '0']"
						:margin="['0', '32rpx']" :showBorder="false">
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">其他收入：</view>
								<view class="">{{ item.profit.qita_shouru }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">注册收入：</view>
								<view class="">{{ item.profit.zhuce_shouru }}</view>
							</view>
						</fui-list-cell>
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">园区注册：</view>
								<view class="">{{ item.profit.yuanqu_zhuce }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">注销收入：</view>
								<view class="">{{ item.profit.zhuxiao_shouru }}</view>
							</view>
						</fui-list-cell>
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">高端收入：</view>
								<view class="">{{ item.profit.gaoduan_shouru }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">外包收入：</view>
								<view class="">{{ item.profit.waibao_shouru }}</view>
							</view>
						</fui-list-cell>
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">资质收入：</view>
								<view class="">{{ item.profit.zizhi_shouru }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">代账费用：</view>
								<view class="">{{ item.profit.daizhang_feiyong }}</view>
							</view>
						</fui-list-cell>
						<fui-list-cell :padding="['12px', '32rpx']">
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">刻章毛利：</view>
								<view class="">{{ item.profit.kezhang_maoli }}</view>
							</view>
							<view class="fs-flex fs-align__center">
								<view class="fs-color__label">社保公积金：</view>
								<view class="">{{ item.profit.shebao_gongjijin }}</view>
							</view>
						</fui-list-cell>
					</fui-card>
				</view>
			</fui-card>

			<fui-card title="其他信息" :margin="['32rpx', '24rpx']">
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">辅助人员：</view>
					<view class="">{{ info.support_renew_name }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">服务详情：</view>
					<view class="">{{ info.service_detail }}</view>
				</fui-list-cell>
				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">支付途径：</view>
					<view class="">{{ info.payment_way }}</view>
				</fui-list-cell>

				<fui-list-cell :padding="['12px', '32rpx']">
					<view class="fs-color__subtitle">备注：</view>
					<view class="">{{ info.remark }}</view>
				</fui-list-cell>
			</fui-card>
		</template>
		<fui-load-ani v-if="loading" type="3" isFixed maskColor="rgba(0,0,0,0.1)"></fui-load-ani>
	</view>
</template>

<script setup>
	import { onLoad, onShareAppMessage } from '@dcloudio/uni-app';
	import { fetchDetailInfo } from '@/common/api/index.js';
	import { ref } from 'vue';
	import { add, subtract } from 'pixiu-number-toolkit';

	const loading = ref(false);
	const id = ref('');
	onLoad((opt) => {
		if (opt.id) {
			id.value = opt.id;
			getDetail();
		}
	});

	const info = ref();
	async function getDetail() {
		loading.value = true;
		const { success, data } = await fetchDetailInfo(id.value).catch(() => {
			loading.value = false;
		});

		if (success) {
			data.products.forEach((item) => {
				const {
					baoshui_ruanjian = 0, jiaji_feiyong = 0, kezhang_chengben = 0, qudao_chengben = 0,
						shuzi_zhengshu = 0, yuanqu_dizhi = 0
				} = item.cost;
				item.costTotal = add(Number(baoshui_ruanjian), Number(jiaji_feiyong), Number(kezhang_chengben),
					Number(qudao_chengben), Number(shuzi_zhengshu), Number(yuanqu_dizhi));

				const {
					qita_shouru = 0,
						zhuce_shouru = 0,
						yuanqu_zhuce = 0,
						zhuxiao_shouru = 0,
						gaoduan_shouru = 0,
						waibao_shouru = 0,
						zizhi_shouru = 0,
						daizhang_feiyong = 0,
						kezhang_maoli = 0,
						shebao_gongjijin = 0
				} = item.profit;
				item.profitTotal = add(
					Number(qita_shouru),
					Number(zhuce_shouru),
					Number(yuanqu_zhuce),
					Number(zhuxiao_shouru),
					Number(gaoduan_shouru),
					Number(waibao_shouru),
					Number(zizhi_shouru),
					Number(daizhang_feiyong),
					Number(kezhang_maoli),
					Number(shebao_gongjijin)
				);
			});
			info.value = data;
			loading.value = false;
		}
	}

	function companyTypeFormat(value) {
		if (value === undefined || value === '') return '';
		const obj = {
			0: '个体',
			1: '小规模纳税人',
			2: '一般纳税人'
		};

		const str = obj[value];
		if (!str) {
			return '';
		} else {
			return str;
		}
	}

	onShareAppMessage(() => {
		return {
			title: '捷报Hub'
		}
	})
</script>

<style></style>